#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
营销方案生成系统配置文件
"""

import os
from datetime import timedelta

class Config:
    """基础配置类"""
    
    # 基本配置
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'marketing-ai-system-2024'
    
    # JSON配置
    JSON_AS_ASCII = False
    JSONIFY_PRETTYPRINT_REGULAR = True
    
    # CORS配置
    CORS_ORIGINS = [
        'http://localhost:3001',
        'http://localhost:5173',
        'http://127.0.0.1:3001',
        'http://127.0.0.1:5173',
        'http://192.168.0.88:8080'
    ]
    
    # 数据存储配置
    DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
    REQUIREMENTS_FILE = os.path.join(DATA_DIR, 'requirements.json')
    
    # 文件上传配置
    MAX_CONTENT_LENGTH = 16 * 1024 * 1024  # 16MB
    UPLOAD_FOLDER = os.path.join(DATA_DIR, 'uploads')
    
    # API配置
    API_VERSION = 'v1'
    API_PREFIX = '/api'
    
    # 分页配置
    DEFAULT_PAGE_SIZE = 20
    MAX_PAGE_SIZE = 100
    
    @staticmethod
    def init_app(app):
        """初始化应用配置"""
        # 确保数据目录存在
        os.makedirs(Config.DATA_DIR, exist_ok=True)
        os.makedirs(Config.UPLOAD_FOLDER, exist_ok=True)


class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True
    

class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False
    

class TestingConfig(Config):
    """测试环境配置"""
    TESTING = True
    DEBUG = True


# 配置字典
config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig,
    'default': DevelopmentConfig
}